﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Configuration;

namespace sushi.Models
{
    public class Entities: DbContext
    {
        public DbSet<Author> Authors { get; set; }
        public DbSet<Post> Posts { get; set; }
        public DbSet<Comment> Comments { get; set; }
        public DbSet<Category> Categories { get; set; }
        public DbSet<Visitor> Visitors { get; set; }


        /// <summary>
        /// If AppSettings IsDesigningEntities Exists and is True, The model is regenerated every time the application is Build
        /// </summary>
        /// <param name="modelBuilder"></param>
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            Boolean debugmode = false;
            if (Boolean.TryParse(ConfigurationManager.AppSettings["IsDesigningEntities"], out debugmode))
            {
                if (debugmode)
                {
                    modelBuilder.Conventions.Remove<IncludeMetadataConvention>();        
                    //Habría que cargar un SampleData
                }
            }
            
            
        }
    }
}